<?php
declare (strict_types=1);

namespace app\command;



use app\common\model\User;
use app\common\model\UserLevel;
use think\console\Command;
use think\console\Input;
use think\console\Output;



class Level extends Command
{
    protected function configure()
    {

        $this->setName('level')->setDescription('level');
    }

    protected function execute(Input $input, Output $output)
    {

        $userLevelModel = new UserLevel();
        $userModel = new User();
        $userLevelList = $userLevelModel->where('end_time','<',time())->where('status','=',1)->select()->toArray();
        if ($userLevelList){
            $levelModel  = new \app\common\model\Level();
            $levelInfo = $levelModel->where(['level' => 0])->find();
            foreach ($userLevelList as $value){
                $userLevelModel->where(['id' =>$value['id'] ])->update(['status' => 1]);
                $userModel->where(['id' => $value['uid']])->update(['level_id' => $levelInfo['id'],'level_name'=>$levelInfo['name']]);
            }
        }
    }

    /**
     * execute()方法 就是 运行该命令行类的时候要执行的具体业务逻辑代码
     */

}